import { create } from "zustand";
import { combine } from "zustand/middleware";

// 定义用户模块状态
const userState = {
  user: null,
  login: (name) => ({ user: { name } }),
};

// 定义主题模块状态
const themeState = {
  theme: "light",
  toggleTheme: () => ({ theme: "dark" }),
};

export const useCombineStore = create(
  combine({ ...userState, ...themeState }, (set) => ({
    // 需要重写方法
    login: (name) => set(userState.login(name)),
    toggleTheme: () => set(themeState.toggleTheme()),
  }))
);
